home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / CompareCells.java < prev    next >
Text File  |  1998-08-21  |  4KB  |  139 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.util.BitSet;
  4.  
  5. // 07/14/97    LAB    Separeated from Multilist.java. Made public to accommodate future
  6. //                extendibility of the MultiList class.
  7.  
  8. /**
  9.  * This is a helper class to the MultiList class.
  10.  * It is used to compare Cells of the MultiList.
  11.  * @version 1.1, July 14, 1997
  12.  * @author Symantec
  13.  */
  14. public abstract class CompareCells
  15.     implements CompareFuncCB
  16. {
  17.     /**
  18.      * Constructs a CompareCells object.
  19.      */
  20.     public CompareCells() {
  21.     }
  22.     /**
  23.      * Compares the value of two objects.
  24.      * @param o1 the first object
  25.      * @param o2 the second object
  26.      * @return 0 if the object's values are equal, less than 0 if the first
  27.      * object's value is less than the second object's value, and greater
  28.      * than 0 if the first object's value is greater than the second
  29.      * object's value
  30.      */
  31.     public abstract int compareObjects(Object o1, Object o2);
  32.  
  33.     /**
  34.      * By default, determines whether the first object's value is less than
  35.      * the second's. Calling the <code>reverse</code> method toggles between
  36.      * the default behavior and determining the if the first object's value
  37.      * is greater than or equal to the second's.
  38.      * @param o1 the first object
  39.      * @param o2 the second object
  40.      * @see #reverse
  41.      */
  42.     public boolean lessThan(Object o1, Object o2)
  43.     {
  44.         int compareResult = compareObjects(o1,o2);
  45.         if (lessOrBig)
  46.             return compareResult < 0;
  47.         return compareResult >= 0;
  48.     }
  49.  
  50.     /**
  51.      * Notes which rows are hilighted before a sort is performed.
  52.      * @param bs flags indicating which rows are hilighted in the MultiList
  53.      */
  54.     public void setCurrentBitSet(BitSet bs)
  55.     {
  56.         this.bs = bs;
  57.     }
  58.  
  59.     /**
  60.      * Notes which row is selected before a sort is performed.
  61.      * @param selRow the zero-relative index of the currently selected row
  62.      * @see #getSelectedRow
  63.      */
  64.     public void setSelectedRow(int selRow)
  65.     {
  66.         this.selRow = selRow;
  67.     }
  68.  
  69.     /**
  70.      * Gets the row which has been noted as selected.
  71.      * @see #setSelectedRow
  72.      */
  73.     public int getSelectedRow()
  74.     {
  75.         return selRow;
  76.     }
  77.  
  78.     /**
  79.      * Exchanges the compared values (rows) in the two given objects.
  80.      * @param o1 the first object, a Matrix
  81.      * @param o2 the second object, a Matrix
  82.      */
  83.     public void callBackSwap(Object o1, Object o2)
  84.     {
  85.         Matrix m1 = (Matrix)o1;
  86.         Matrix m2 = (Matrix)o2;
  87.         boolean b1 = bs.get(m1.row);
  88.         boolean b2 = bs.get(m2.row);
  89.  
  90.         if (b1)
  91.             bs.set(m2.row);
  92.         else
  93.             bs.clear(m2.row);
  94.  
  95.         if (b2)
  96.             bs.set(m1.row);
  97.         else
  98.             bs.clear(m1.row);
  99.  
  100.         if (selRow == m1.row)
  101.             selRow = m2.row;
  102.         else if (selRow == m2.row)
  103.             selRow = m1.row;
  104.     }
  105.  
  106.     /**
  107.      * Toggles the comparison done by the <code>lessThan</code> method.
  108.      * By default, the <code>lessThan</code> method determines whether the
  109.      * first object's value is less than the second's.
  110.      * Calling the this method toggles between toggles netween that behavior
  111.      * and determining the if the first object's value is greater than or
  112.      * equal to the second's.
  113.      * @see #lessThan
  114.      */
  115.     public void reverse()
  116.     {
  117.         lessOrBig = !lessOrBig;
  118.     }
  119.  
  120.     /**
  121.      * A set of flags that indicates which rows are hilighted in the MultiList.
  122.      */
  123.     protected BitSet        bs;
  124.     /**
  125.      * The zero-relative index of the currently selected row, or -1 if none.
  126.      */
  127.     protected int            selRow = -1;
  128.     /**
  129.      * The current compare mode for the <code>lessThan</code> method.
  130.      * If true, the <code>lessThan</code> method determines whether the
  131.      * first object's value is less than the second's.
  132.      * If false, the <code>lessThan</code> method determines whether the
  133.      * first object's value is is greater than or equal to the second's.
  134.      * @see #lessThan
  135.      * @see #reverse
  136.      */
  137.     protected boolean        lessOrBig = true;
  138. }
  139.